package com.samoiloff.ui.btns.simple {
	import Boolean;
	import caurina.transitions.Tweener;

	import flash.display.DisplayObject;
	import flash.display.SimpleButton;
	import flash.events.EventDispatcher;
	import flash.events.MouseEvent;

	/**
	 * @author Alexander Slavshik <as.kvint@gmail.com>
	 * created 16.03.2010
	 */
	public class SimpleButtonController extends EventDispatcher {
		private var _mc:SimpleButton;
		private var _enabled:Boolean = true;

		public function SimpleButtonController(mc:SimpleButton, handCursor:Boolean = false) {
			_mc = mc;
			_mc.useHandCursor = handCursor;
			_mc.addEventListener(MouseEvent.CLICK, mouseHandler);			_mc.addEventListener(MouseEvent.ROLL_OUT, mouseHandler);			_mc.addEventListener(MouseEvent.ROLL_OVER, mouseHandler);
		}

		private function mouseHandler(event:MouseEvent):void {
			dispatchEvent(event);
		}
		public function destroy():void{
			_mc.removeEventListener(MouseEvent.CLICK, mouseHandler);
			_mc.removeEventListener(MouseEvent.ROLL_OUT, mouseHandler);
			_mc.removeEventListener(MouseEvent.ROLL_OVER, mouseHandler);
			_mc = null;
		}
		public function get enabled():Boolean {
			return _enabled;
		}
		
		public function set enabled(enabled:Boolean):void {
			_enabled = enabled;
			Tweener.addTween(_mc, {_saturation:_enabled ? 1:0, alpha: _enabled ? 1 : 0.6});
			_mc.mouseEnabled = _enabled;
		}
		
		public function get mc(): DisplayObject {
			return _mc;
		}
	}
}
